package edu.cmu.cs.stage3.alice.authoringtool.datatransfer;

import java.awt.datatransfer.DataFlavor;

/**
 * @author Jason Pratt
 */
public class ElementPrototypeReferenceTransferable implements java.awt.datatransfer.Transferable {

 //LOB version using 'mimeType' to create 'java.awt.datatransfer.DataFlavor' produce error in Java 5, changed to 'Class'
 // public final static java.awt.datatransfer.DataFlavor elementPrototypeReferenceFlavor = new java.awt.datatransfer.DataFlavor( java.awt.datatransfer.DataFlavor.javaJVMLocalObjectMimeType + "; class=edu.cmu.cs.stage3.alice.authoringtool.util.ElementPrototype", "elementPrototypeReferenceFlavor" );
 public final static java.awt.datatransfer.DataFlavor elementPrototypeReferenceFlavor
               = new java.awt.datatransfer.DataFlavor(edu.cmu.cs.stage3.alice.authoringtool.util.ElementPrototype.class, "elementPrototypeReferenceFlavor");

 protected java.awt.datatransfer.DataFlavor[] flavors;
 protected edu.cmu.cs.stage3.alice.authoringtool.util.ElementPrototype elementPrototype;

 public ElementPrototypeReferenceTransferable( edu.cmu.cs.stage3.alice.authoringtool.util.ElementPrototype elementPrototype ) {
  this.elementPrototype = elementPrototype;

  flavors = new java.awt.datatransfer.DataFlavor[2];
  flavors[0] = elementPrototypeReferenceFlavor;
  flavors[1] = java.awt.datatransfer.DataFlavor.stringFlavor;
 }

 public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors() {
  return flavors;
 }

 public boolean isDataFlavorSupported( java.awt.datatransfer.DataFlavor flavor ) {
  //LOB for (DataFlavor flavor2 : flavors)
  int t_tam = flavors!=null ? flavors.length : 0;
  for (int i_i=0; i_i<t_tam; i_i++) {
   if( flavor.equals( flavors[i_i] ) ) { //L ( flavor2 )
    return true;
   }
  }
  return false;
 }

 public Object getTransferData( java.awt.datatransfer.DataFlavor flavor ) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException {
  if( flavor.equals( elementPrototypeReferenceFlavor ) ) {
   return elementPrototype;
  } else if( flavor.equals( java.awt.datatransfer.DataFlavor.stringFlavor ) ) {
   return elementPrototype.toString();
  } else {
   throw new java.awt.datatransfer.UnsupportedFlavorException( flavor );
  }
 }

}
